//
//  ZYCAttendanceSingleDetailsSectionView.m
//  ZDSC
//
//  Created by 张威 on 2021/10/26.
//

#import "ZYCAttendanceSingleDetailsSectionView.h"
@interface ZYCAttendanceSingleDetailsSectionView ()
@property (nonatomic, strong) UIView *bgView;

@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *contentLabel;
@property (nonatomic, strong) UIImageView *arrowImageView;
@property (nonatomic, strong) UIView *line;

@end
@implementation ZYCAttendanceSingleDetailsSectionView

- (void)setIs_unfold:(BOOL)is_unfold{
    _is_unfold = is_unfold;
    if (is_unfold) {
        self.arrowImageView.transform = CGAffineTransformMakeRotation(0);
    }else{
        self.arrowImageView.transform = CGAffineTransformMakeRotation(-M_PI_2);
    }
}

- (void)setColorString:(NSString *)colorString{
    _colorString = colorString;
    _titleLabel.textColor = HEX_RGB(colorString);
    _contentLabel.textColor = HEX_RGB(colorString);
}


- (void)setTitleString:(NSString *)titleString{
    _titleString = titleString;
    _titleLabel.text = titleString;
}

- (void)setContentString:(NSString *)contentString{
    _contentString = contentString;
    _contentLabel.text = contentString;
}
 
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = HEX_RGB(@"FFFFFF");
        self.userInteractionEnabled = YES;
        [self addSubview:self.bgView];
        [self addSubview:self.titleLabel];
        [self addSubview:self.contentLabel];
        [self addSubview:self.arrowImageView];
        [self addSubview:self.line];
    
        [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.top.equalTo(self);
            make.height.mas_equalTo(10.0f);
        }];
        
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(15.0f);
            make.top.equalTo(self.bgView.mas_bottom).offset(18.5f);
        }];

        [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.arrowImageView.mas_left).offset(-13.0f);
            make.centerY.equalTo(self.titleLabel);
        }];
        
        [self.arrowImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self).offset(-12.0f);
            make.centerY.equalTo(self.titleLabel);
            make.size.mas_equalTo(CGSizeMake(13.0f, 7.0f));
        }];
        
        [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.equalTo(self);
            make.height.mas_equalTo(1.0f);
        }];
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickTap:)];
        tap.numberOfTouchesRequired = 1;
        tap.numberOfTapsRequired = 1;
        [self addGestureRecognizer:tap];
    }
    return self;
}

- (UIView *)bgView {
    if (!_bgView) {
        _bgView = [[UIView alloc] init];
        _bgView.backgroundColor = HEX_RGB(@"#FAFAFA");
    }
    return _bgView;
}

- (UIView *)line {
    if (!_line) {
        _line = [[UIView alloc] init];
        _line.backgroundColor = HEX_RGB(@"#FAFAFA");
    }
    return _line;
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.font = kCustomFont(@"PingFangSC-Light", 17.0f);
        _titleLabel.textAlignment = NSTextAlignmentLeft;
    }
    return _titleLabel;
}


- (UILabel *)contentLabel {
    if (!_contentLabel) {
        _contentLabel = [[UILabel alloc] init];
        _contentLabel.font = kCustomFont(@"PingFangSC-Light", 17.0f);
        _contentLabel.textAlignment = NSTextAlignmentRight;
    }
    return _contentLabel;
}

- (UIImageView *)arrowImageView {
    if (!_arrowImageView) {
        _arrowImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"down"]];
    }
    return _arrowImageView;
}

- (void)clickTap:(UIGestureRecognizer *)tap{
    if ([self.delegate respondsToSelector:@selector(attendanceSingleDetailsSectionViewDidFold:)]) {
        [self.delegate attendanceSingleDetailsSectionViewDidFold:self];
    }
}
@end
